<!DOCTYPE html>
<html>

<head>
	<meta charset="utf-8">
	<title></title>
	<link rel="stylesheet" href="../../component/pear/css/pear.css" />
</head>

<body class="pear-container">
	<div class="layui-card">
		<div class="layui-card-body">
			<form class="layui-form" action="">
				<div class="layui-form-item">
					<!-- <label class="layui-form-label">用户名</label>
						<div class="layui-input-inline">
							<input type="text" name="realName" placeholder="" class="layui-input">
						</div> -->
					<label class="layui-form-label">选择主题</label>
					<div class="layui-input-inline">
						<select id="Theme" name="Theme" lay-verify="required">
							<option value=""></option>
							<option value="空间">空间</option>
							<option value="动力">动力</option>
							<option value="油耗">油耗</option>
							<option value="操控">操控</option>
							<option value="内饰">内饰</option>
							<option value="舒适性">舒适性</option>
							<option value="外观">外观</option>
						</select>
					</div>
					<label class="layui-form-label">选择情感</label>
					<div class="layui-input-inline">
						<select id="Emotional" name="Emotional" lay-verify="required">
							<option value=""></option>
							<option value="满意">满意</option>
							<option value="不满意">不满意</option>
						</select>
					</div>
					<!-- <div class="layui-input-inline">
							<input type="text" name="username" placeholder="" class="layui-input">
						</div> -->
					<button class="pear-btn pear-btn-md pear-btn-primary" lay-submit lay-filter="user-query">
						<i class="layui-icon layui-icon-search"></i>
						查询
					</button>
					<button type="reset" class="pear-btn pear-btn-md">
						<i class="layui-icon layui-icon-refresh"></i>
						重置
					</button>
				</div>
			</form>
		</div>
	</div>
	<div class="layui-card">
		<div class="layui-card-body">
			<table id="user-table" lay-filter="user-table"></table>
		</div>
	</div>

	<script type="text/html" id="user-toolbar">
			<!-- <button class="pear-btn pear-btn-primary pear-btn-md" lay-event="add">
				<i class="layui-icon layui-icon-add-1"></i>
				新增
			</button> -->
	<button class="pear-btn pear-btn-danger pear-btn-md" lay-event="batchRemove">
		<i class="layui-icon layui-icon-delete"></i>
		删除
	</button>
	</script>

	<script type="text/html" id="user-bar">
			<button class="pear-btn pear-btn-primary pear-btn-sm" lay-event="edit"><i
					class="layui-icon layui-icon-edit"></i></button>
			<button class="pear-btn pear-btn-danger pear-btn-sm" lay-event="remove"><i
					class="layui-icon layui-icon-delete"></i></button>
			<button class="pear-btn pear-btn-sm" id="more{{d.userId}}"><i class="layui-icon layui-icon-triangle-d"></i></button>
		</script>
	<script type="text/html" id="user-from">
		{{#if (d.Source == 0) { }}
			<span>爬取</span>
			{{# }else if(d.sex == 1){ }}
				<span>用户上传</span>
				{{# } }}
		</script>

	<script type="text/html" id="user-createTime">
		{{layui.util.toDateString(d.createTime, 'yyyy-MM-dd')}}
		</script>

	<script type="text/plain" id="moreTool">
			[
		[{txt: "Progerss", event: "progress"}]
		[{txt: "Resolve", event: "resolve"}]
		[{txt: "Reopen", event: "reopen"}]
		[{txt: "Close", event: "close"}]
		]
	</script>


	<div style="display: none;">
		<div class="layer-top">
			<br />
			<h3>上侧弹层内容...</h3>
		</div>
	</div>

	<script src="../../component/layui/layui.js"></script>
	<script src="../../component/pear/pear.js"></script>
	<script>
		const host = "http://localhost/LSTM_car_comment/public/";
		layui.use(['table', 'form', 'jquery', 'drawer', 'dropdown'], function () {
			let table = layui.table;
			let form = layui.form;
			let $ = layui.jquery;
			let drawer = layui.drawer;
			let dropdown = layui.dropdown;

			let MODULE_PATH = host + "web/data/";

			let cols = [
				[{
					type: 'checkbox'
				},
				// {
				// 	title: '评论id',
				// 	field: 'Pid',
				// 	align: 'center',
				// 	// width: 100
				// },
				{
					title: '评论',
					field: 'Content',
					align: 'center',
					width: 500

				},
				{
					title: '车型',
					field: 'CarModel',
					align: 'center',
					width: 120
				},
				{
					title: '情感预测',
					field: 'Emotional',
					align: 'center'
				},
				{
					title: '主题预测',
					field: 'Theme',
					align: 'center',
					// templet: '#user-enable'
				},
				{
					title: '关键词',
					field: 'KeyWords',
					align: 'center',
					// templet: '#user-login'
				},
				{
					title: '提交日期',
					field: 'ReleaseDate',
					align: 'center',
					width: 110
					// templet: '#user-createTime'
				},
				{
					title: '来源',
					field: 'Source',
					align: 'center',
					templet: '#user-from'
				},
				{
					title: '操作',
					toolbar: '#user-bar',
					align: 'left',
					width: 170
				}
				]
			]
			var themeValue = $("#Theme").val();
			var emotionalValue = $("#Emotional").val();
			// alert(themeValue);
			console.log(themeValue);
			console.log(emotionalValue);
			table.render({
				elem: '#user-table',
				url: host + 'web/data/finddata',
				where: { Theme: themeValue, Emotional: emotionalValue },
				page: true,
				cols: cols,
				skin: 'line',
				toolbar: '#user-toolbar',
				defaultToolbar: [{
					layEvent: 'refresh',
					icon: 'layui-icon-refresh',
				}, 'filter', 'print', 'exports'],
				done: function (res) {
					for (var i = 0; i < res.data.length; i++) {
						if (res.data[i].userId == "5" || res.data[i].userId == "8") {
							$("#more" + res.data[i].userId).hide();
							continue;
						}

						dropdown.suite("#more" + res.data[i].userId, {
							align: 'left',
							data: res.data[i],
							templateMenu: "moreTool",
						});
					}
				}
			});

			table.on('tool(user-table)', function (obj) {
				if (obj.event === 'remove') {
					window.remove(obj);
				} else if (obj.event === 'edit') {
					window.edit(obj);
				} else if (obj.event === "progress") {
					layer.msg(obj.event);
				} else if (obj.event === "resolve") {
					layer.msg(obj.event);
				} else if (obj.event === "reopen") {
					layer.msg(obj.event);
				} else if (obj.event === "close") {
					layer.msg(obj.event);
				}
			});

			table.on('toolbar(user-table)', function (obj) {
				if (obj.event === 'add') {
					window.add();
				} else if (obj.event === 'refresh') {
					window.refresh();
				} else if (obj.event === 'batchRemove') {
					window.batchRemove(obj);
				}
			});

			form.on('submit(user-query)', function (data) {
				table.reload('user-table', {
					where: {
						Theme: data.field.Theme,
						Emotional: data.field.Emotional,
					}
				})
				return false;
			});

			form.on('switch(user-enable)', function (obj) {
				layer.tips(this.value + ' ' + this.name + '：' + obj.elem.checked, obj.othis);
			});

			window.add = function () {
				drawer.open({
					direction: "top",
					dom: ".layer-top",
					distance: "30%"
				});
			}

			window.edit = function (obj) {
				layer.msg("修改");
			}

			window.remove = function (obj) {
				layer.confirm('确定要删除该评论？', {
					icon: 3,
					title: '提示'
				}, function (index) {
					layer.close(index);
					let loading = layer.load();
					$.ajax({
						url: MODULE_PATH + "remove?Pid=" + obj.data.Pid,
						dataType: 'json',
						type: 'delete',
						success: function (result) {
							layer.close(loading);
							layer.msg("删除成功", {
								icon: 1,
								time: 1000
							}, function () {
								obj.del();
								table.reload('user-table');
							});
						}
					})
				});
			}

			window.batchRemove = function (obj) {
				let data = table.checkStatus(obj.config.id).data;
				if (data.length === 0) {
					layer.msg("未选中数据", {
						icon: 3,
						time: 1000
					});
					return false;
				}
				let ids = "";
				for (let i = 0; i < data.length; i++) {
					ids += data[i].userId + ",";
				}
				ids = ids.substr(0, ids.length - 1);
				layer.confirm('确定要删除这些评论吗？', {
					icon: 3,
					title: '提示'
				}, function (index) {
					layer.close(index);
					let loading = layer.load();
					$.ajax({
						url: MODULE_PATH + "remove/" + ids,
						dataType: 'json',
						type: 'delete',
						success: function (result) {
							layer.close(loading);
							if (result.success) {
								layer.msg(result.msg, {
									icon: 1,
									time: 1000
								}, function () {
									table.reload('user-table');
								});
							} else {
								layer.msg(result.msg, {
									icon: 2,
									time: 1000
								});
							}
						}
					})
				});
			}

			window.refresh = function (param) {
				table.reload('user-table');
			}
		})
	</script>
</body>

</html>